package com.heima.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.mapper.SkuMapper;
import com.heima.mapper.skuClassMapper;
import com.heima.pojo.dto.pageDTO;
import com.heima.pojo.dto.SkuClass;
import com.heima.pojo.vo.PageVo;
import com.heima.service.skuClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class skuClassServiceImpl extends ServiceImpl<skuClassMapper, SkuClass> implements skuClassService {

    @Autowired
    private skuClassMapper skuClassMapper;

    @Autowired
    private SkuMapper skuMapper;

    @Override
    public void add(SkuClass skuClass) {
        SkuClass sku = new SkuClass();
        sku.setParentId(0);
        sku.setClassName(skuClass.getClassName());
        skuClassMapper.add(sku);
    }

    @Override
    public PageVo<SkuClass> query(pageDTO pageDTO) {
        String className = pageDTO.getClassName();
        Page page = new Page<>(pageDTO.getPageIndex(), pageDTO.getPageSize());
        Page<SkuClass> p = lambdaQuery()
                .like(className != null, SkuClass::getClassName, className)
                .page(page);
        PageVo pageVo = new PageVo<>();
        pageVo.setPageIndex(pageDTO.getPageIndex());
        pageVo.setPageSize(pageDTO.getPageSize());
        pageVo.setTotalPage(p.getPages());
        pageVo.setTotalCount(p.getTotal());
        pageVo.setCurrentPageRecords(p.getRecords());
        log.info("接收到的参数为{}",pageVo);
        return pageVo;
    }

}
